﻿@{
    ViewBag.Title = "Common Command";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
        <ol class="breadcrumb">
            <li><a href="/Home/Home">Home</a></li>
            <li><a href="/Common/CommonIntoduction"> Sanelib Common</a></li>
            <li class="active">Command</li>
        </ol>
            
            <div id="introduction">
                <h1 class="text-left">Command</h1>
                <p>Command  has main content in Common . Command is Processing By User.In Command have Set all Values of setter and getter methods.After all Value is set Command contains GetAggregateId and Validate method.</p>
                <p>First 'GetAggregateId' method return Id That Derived From 'System.Guid' that is Use to Generate 32-bit Unique Id.</p>
                <pre><code>public Guid  GetAggregateId()<br/>{<br/> return Guid <br/>}<br/></code></pre>
                <p>Second 'Validate' method has no argument.'validate' method contain ErrorResult() that Check data like in SaveMember MemberName is Must Be Enter,Date Of birth is Not FutureDate etc.</p>
                <pre><code>public ErrorResult Validate()<br />{<br/>var validationResult = new ErrorResult();<br/>if (string.IsNullOrWhiteSpace(Name))<br/>validationResult.AddError("Name", " should not be empty.");<br/>if (DateOfBirth > DateTime.Now)<br/>validationResult.AddError("DateOfBirth", " is invalid.");<br/>return validationResult<br/>}<br/></code></pre>
                <p>return true if all the Validation credential Perform if exception Occure it return validationresult.AddError(key,string) in System.Dto ErrorResult.cs</p>
                <pre><code>public void AddError(string key, string value)<br />{<br/>lock (Lock)<br />{<br/>var obj = ValidationObjects.FirstOrDefault(x => x.Key == key);<br/>if (obj == null)<br/>{<br/>obj = new ValidationObject { Key = key };<br/>ValidationObjects.Add(obj);<br/>}<br/>obj.Lines.Add(value);<br/>}<br/>}</code></pre>
                <p>In this AddError there are two argument key and Value.the value of key like Name,Date Of Birth etc and value like "Name is Empty","Date of Birth is Invalid" etc.</p>
                <p>Command have the CommandCoordinator that contains Interface of ICommand.</p>
                <pre><code>public interface ICommand<br/>{<br/>Guid GetAggregateId();<br/>ErrorResult Validate();<br/>}</code></pre>
                <p>In ICommand interface Define two abstract Method GetAggregateId That type of Guid and Validate method type of ErrorResult.</p>
                <p>CommandCoordinator that also Contain ICommandProcessor Interface That Is Process the Command.</p>
                <pre><code>public interface ICommandProcessor &lt;TCommand&gt; where TCommand : ICommand<br />{<br />dynamic Process(TCommand command);<br />}</code></pre>
                <p>Commands Contains AthorizationCommand, MemberCommand, ReceivedFileCommand, TrackLogCommand.</p>
                <p>Example Of RegisterMemberCard</p>
                <pre><code>public class RegisterMemberCard : ICommand<br/>{<br/>public Guid? Id { get; set; }<br/>public string TagId { get; set; }<br/>public Guid GetAggregateId()<br/>{<br/>return Id.GetValueOrDefault();<br/>}<br/>public ErrorResult Validate()<br/>{<br/>var validationResult = new ErrorResult();<br/>if(!Id.HasValue)<br/>validationResult.AddError("Code", "is empty.");<br/>if (string.IsNullOrEmpty(TagId))<br/>validationResult.AddError("TagId", "is empty.");<br/>return validationResult;<br/>}<br/>}</code></pre>
              <p>In AboveExample RegisterMemberCard extend by ICommand Interface that Implement two Methods GetAggregateId and Validate.GetAggregateId Return Guid to ICommandRecorder that Record Command and Validate Method return ValidationResult in IntegrationTestBase.cs and also SmartApiController.</p></div>
            